#!/bin/bash
#

# 设置阈值（可调整为参数输入）
threshold=10

echo "检查磁盘使用率超过 ${threshold}% 的分区："
echo "========================================"

df -hT | grep "^/dev" | while read line; do
    # 使用单个awk命令提取所有字段，提高效率
    usage=$(echo "$line" | awk '{gsub(/%/, "", $6); print $6}')
    mount_point=$(echo "$line" | awk '{print $NF}')
    total=$(echo "$line" | awk '{print $3}')
    available=$(echo "$line" | awk '{print $5}')
    filesystem=$(echo "$line" | awk '{print $1}')
    fstype=$(echo "$line" | awk '{print $2}')
    
    # 检查使用率是否超过阈值
    if [ "$usage" -ge "$threshold" ]; then
        echo "文件系统: $filesystem"
        echo "类型: $fstype"
        echo "挂载点: $mount_point"
        echo "总容量: $total"
        echo "已使用: $usage%"
        echo "可用空间: $available"
        echo "----------------------------------------"
    fi
done
